using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Scenario.Modeler.XSD
{
	/// <summary>
	/// Summary description for XSDInference.
	/// </summary>
	public class XSDInference : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.Button btnTools;
		private System.Windows.Forms.TextBox txtTool;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btnXMLFile;
		private System.Windows.Forms.TextBox txtXMLFile;
		private System.Windows.Forms.Button btnXSDFile;
		private System.Windows.Forms.Label XSDFile;
		private System.Windows.Forms.TextBox txtXSDFile;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Label processResults;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public XSDInference()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtTool = new System.Windows.Forms.TextBox();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.btnTools = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.btnXMLFile = new System.Windows.Forms.Button();
			this.txtXMLFile = new System.Windows.Forms.TextBox();
			this.btnXSDFile = new System.Windows.Forms.Button();
			this.XSDFile = new System.Windows.Forms.Label();
			this.txtXSDFile = new System.Windows.Forms.TextBox();
			this.btnStart = new System.Windows.Forms.Button();
			this.processResults = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(664, 32);
			this.label1.TabIndex = 0;
			this.label1.Text = "E\' possibile utilizzare direttamente il codice microsoft in quanto quest\'ultima r" +
				"ilascia il sorgente del tool";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 88);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(368, 24);
			this.label2.TabIndex = 1;
			this.label2.Text = "tool da utilizzare.";
			// 
			// txtTool
			// 
			this.txtTool.Location = new System.Drawing.Point(16, 104);
			this.txtTool.Name = "txtTool";
			this.txtTool.Size = new System.Drawing.Size(544, 22);
			this.txtTool.TabIndex = 2;
			this.txtTool.Text = "C:\\mySoftware\\Tools\\XSDInference\\bin\\infer.exe";
			// 
			// btnTools
			// 
			this.btnTools.Location = new System.Drawing.Point(568, 104);
			this.btnTools.Name = "btnTools";
			this.btnTools.Size = new System.Drawing.Size(32, 24);
			this.btnTools.TabIndex = 3;
			this.btnTools.Text = "...";
			this.btnTools.Click += new System.EventHandler(this.btnTools_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 168);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(552, 16);
			this.label3.TabIndex = 4;
			this.label3.Text = "XMLFile da utilizzare per generare il file XSD";
			// 
			// btnXMLFile
			// 
			this.btnXMLFile.Location = new System.Drawing.Point(576, 184);
			this.btnXMLFile.Name = "btnXMLFile";
			this.btnXMLFile.Size = new System.Drawing.Size(32, 24);
			this.btnXMLFile.TabIndex = 5;
			this.btnXMLFile.Text = "...";
			this.btnXMLFile.Click += new System.EventHandler(this.btnXMLFile_Click);
			// 
			// txtXMLFile
			// 
			this.txtXMLFile.Location = new System.Drawing.Point(16, 184);
			this.txtXMLFile.Name = "txtXMLFile";
			this.txtXMLFile.Size = new System.Drawing.Size(552, 22);
			this.txtXMLFile.TabIndex = 6;
			this.txtXMLFile.Text = "";
			// 
			// btnXSDFile
			// 
			this.btnXSDFile.Location = new System.Drawing.Point(576, 248);
			this.btnXSDFile.Name = "btnXSDFile";
			this.btnXSDFile.Size = new System.Drawing.Size(40, 23);
			this.btnXSDFile.TabIndex = 7;
			this.btnXSDFile.Text = "...";
			this.btnXSDFile.Click += new System.EventHandler(this.btnXSDFile_Click);
			// 
			// XSDFile
			// 
			this.XSDFile.Location = new System.Drawing.Point(16, 232);
			this.XSDFile.Name = "XSDFile";
			this.XSDFile.Size = new System.Drawing.Size(536, 23);
			this.XSDFile.TabIndex = 8;
			this.XSDFile.Text = "XSDFile";
			// 
			// txtXSDFile
			// 
			this.txtXSDFile.Location = new System.Drawing.Point(16, 248);
			this.txtXSDFile.Name = "txtXSDFile";
			this.txtXSDFile.Size = new System.Drawing.Size(552, 22);
			this.txtXSDFile.TabIndex = 9;
			this.txtXSDFile.Text = "textBox1";
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(16, 288);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(600, 40);
			this.btnStart.TabIndex = 10;
			this.btnStart.Text = "MakeIT";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// processResults
			// 
			this.processResults.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.processResults.Location = new System.Drawing.Point(16, 344);
			this.processResults.Name = "processResults";
			this.processResults.Size = new System.Drawing.Size(600, 72);
			this.processResults.TabIndex = 11;
			this.processResults.Text = "label4";
			// 
			// XSDInference
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(624, 440);
			this.Controls.Add(this.processResults);
			this.Controls.Add(this.btnStart);
			this.Controls.Add(this.txtXSDFile);
			this.Controls.Add(this.XSDFile);
			this.Controls.Add(this.btnXSDFile);
			this.Controls.Add(this.txtXMLFile);
			this.Controls.Add(this.btnXMLFile);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.btnTools);
			this.Controls.Add(this.txtTool);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "XSDInference";
			this.Text = "XSDInference";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnTools_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog openFileDialog1 = new OpenFileDialog();

			openFileDialog1.Filter = "exe files (*.exe)|*.exe";
			openFileDialog1.FilterIndex = 1 ;
			openFileDialog1.RestoreDirectory = true ;

			if(openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				this.txtTool.Text = openFileDialog1.FileName;
			}
		}

		private void btnXMLFile_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog openFileDialog1 = new OpenFileDialog();

			openFileDialog1.Filter = "xml files (*.xml)|*.xml";
			openFileDialog1.FilterIndex = 1 ;
			openFileDialog1.RestoreDirectory = true ;

			if(openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				this.txtXMLFile.Text = openFileDialog1.FileName;
			}
		}

		private void btnXSDFile_Click(object sender, System.EventArgs e)
		{
			SaveFileDialog saveFileDialog1 = new SaveFileDialog();
 
			saveFileDialog1.Filter = "XSD File (*.xsd)|*.xsd"  ;
			saveFileDialog1.FilterIndex = 1 ;
			saveFileDialog1.RestoreDirectory = true ;
 
			if(saveFileDialog1.ShowDialog() == DialogResult.OK)
			{
				this.txtXSDFile.Text = saveFileDialog1.FileName;
			}
		}

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			string sArgs = this.txtXMLFile.Text + " -o " + this.txtXSDFile.Text;
			System.Diagnostics.ProcessStartInfo psi =new System.Diagnostics.ProcessStartInfo(this.txtTool.Text,sArgs);
			psi.RedirectStandardOutput = true;
			psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
			psi.UseShellExecute = false;
			System.Diagnostics.Process listFiles;
			listFiles = System.Diagnostics.Process.Start(psi);
			System.IO.StreamReader myOutput = listFiles.StandardOutput;
			listFiles.WaitForExit(2000);
			//if (listFiles.HasExited)
			//{
				string output = myOutput.ReadToEnd();
				this.processResults.Text = output;
			//}
		}
	}
}
